<template>
  <div class="members-consumption">
    <h3>消费明细</h3>

    <!-- 筛选查询 -->
    <el-form :inline="true" class="demo-form-inline">
      <el-form-item label="订单编号">
        <el-input v-model="orderNumber" placeholder="请输入订单编号"></el-input>
      </el-form-item>
      <el-form-item label="消费时间">
        <el-date-picker
          v-model="dateRange"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">查询</el-button>
      </el-form-item>
    </el-form>

    <!-- 消费记录列表 -->
    <el-table :data="tableData" style="width: 100%">
      <el-table-column prop="orderNumber" label="订单编号" width="180"></el-table-column>
      <el-table-column prop="productName" label="商品名称" width="180"></el-table-column>
      <el-table-column prop="consumeAmount" label="消费金额" width="180"></el-table-column>
      <el-table-column prop="consumeTime" label="消费时间" width="180"></el-table-column>
      <el-table-column fixed="right" label="操作" width="100">
        <template #default="scope">
          <el-button @click="handleView(scope.row)" type="text" size="small">查看</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 查看消费详情弹窗 -->
    <el-dialog v-model="dialogVisible" title="消费详情" width="40%">
      <div v-if="selectedRecord" class="record-detail">
        <p><strong>订单编号：</strong>{{ selectedRecord.orderNumber }}</p>
        <p><strong>商品名称：</strong>{{ selectedRecord.productName }}</p>
        <p><strong>消费金额：</strong>{{ selectedRecord.consumeAmount }} 元</p>
        <p><strong>消费时间：</strong>{{ selectedRecord.consumeTime }}</p>
      </div>
      <template #footer>
        <el-button @click="dialogVisible = false">关闭</el-button>
      </template>
    </el-dialog>
  </div>
</template>

<script setup>
import { ref } from 'vue'

// 查询条件
const orderNumber = ref('')
const dateRange = ref([])

// 表格数据
const tableData = ref([
  {
    orderNumber: '001',
    productName: '商品1',
    consumeAmount: '100.00',
    consumeTime: '2023-01-01 10:00:00'
  },
  // 可继续添加其他消费记录...
])

// 弹窗控制
const dialogVisible = ref(false)
const selectedRecord = ref(null)

// 查询方法（可对接接口）
const onSubmit = () => {
  console.log('查询条件:', orderNumber.value, dateRange.value)
}

// 打开弹窗并设置当前记录
const handleView = (row) => {
  selectedRecord.value = row
  dialogVisible.value = true
}
</script>

<style scoped>
.record-detail p {
  margin-bottom: 10px;
  font-size: 14px;
}
</style>